<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta name="Content-Type" content="text/html; charset=UTF-8" />
<title>Class: ActionController::TestCase</title>
<link rel="stylesheet" href="../css/style.css" type="text/css" media="screen" charset="utf-8" />
<link rel="stylesheet" href="../css/common.css" type="text/css" media="screen" charset="utf-8" />

<script type="text/javascript" charset="utf-8">
  relpath = '..';
  if (relpath != '') relpath += '/';
</script>
<script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/app.js"></script>

  </head>
  <body>
    <div id="header">
      <div id="menu">
  
    <a href="../_index.html">Index (T)</a> &raquo; 
    ActionController
     &raquo; 
    <span class="title">TestCase</span>
  
</div>

      <div id="search">
  <a id="class_list_link" href="#">Namespace List</a>
  <a id="method_list_link" href="#">Method List</a>
  <a id ="file_list_link" href="#">File List</a>
</div>

      <div class="clear"></div>
    </div>
    
    <iframe id="search_frame"></iframe>
    
    <div id="content"><h1>Class: ActionController::TestCase 
  
  
</h1>

<dl class="box">
  
    <dt class="r1">Inherits:</dt>
    <dd class="r1">
      <span class="inheritName">Object</span>
      
      </dd>
    
  
  
    
  
    
  
  
    <dt class="r2 last">Defined in:</dt>
    <dd class="r2 last">shoulda_macros/controller_macros.rb</dd>
  
</dl>
<div class="clear"></div>

<h2>Overview</h2><div class="docstring">
  <div class="discussion">
    <h1>Functional test Shoulda macros</h1>
<p>
These macros are very useful. Use them.
</p>
<h2>Example</h2>
<pre class="code">
  <span class='class class kw'>class</span> <span class='NotesControllerTest constant id'>NotesControllerTest</span> <span class='lt op'>&lt;</span> <span class='ActionController constant id'>ActionController</span><span class='colon2 op'>::</span><span class='TestCase constant id'>TestCase</span>
    <span class='setup identifier id'>setup</span> <span class='symbol val'>:activate_authlogic</span>

    <span class='as_a_logged_in_user identifier id'>as_a_logged_in_user</span> <span class='do do kw'>do</span>
      <span class='who_can_manage identifier id'>who_can_manage</span> <span class='symbol val'>:notes</span> <span class='do do kw'>do</span>
        <span class='context identifier id'>context</span> <span class='string val'>&quot;on GET to /notes/new&quot;</span> <span class='do do kw'>do</span>
          <span class='setup identifier id'>setup</span> <span class='lbrace token'>{</span> <span class='get identifier id'>get</span> <span class='symbol val'>:new</span> <span class='rbrace token'>}</span>
          <span class='should_not_set_the_flash identifier id'>should_not_set_the_flash</span>
          <span class='should_render_template identifier id'>should_render_template</span> <span class='symbol val'>:new</span>
        <span class='end end kw'>end</span>
        <span class='dot3 op'>...</span>
      <span class='end end kw'>end</span>

      <span class='who_cannot_manage identifier id'>who_cannot_manage</span> <span class='symbol val'>:notes</span> <span class='do do kw'>do</span>
        <span class='context identifier id'>context</span> <span class='string val'>&quot;on GET to /notes/new&quot;</span> <span class='do do kw'>do</span>
          <span class='setup identifier id'>setup</span> <span class='lbrace token'>{</span> <span class='get identifier id'>get</span> <span class='symbol val'>:new</span> <span class='rbrace token'>}</span>
          <span class='should_be_denied_as_user identifier id'>should_be_denied_as_user</span>
        <span class='end end kw'>end</span>

        <span class='context identifier id'>context</span> <span class='string val'>&quot;given a note&quot;</span> <span class='do do kw'>do</span>
          <span class='setup identifier id'>setup</span> <span class='lbrace token'>{</span> <span class='@note ivar id'>@note</span> <span class='assign token'>=</span> <span class='Factory constant id'>Factory</span><span class='lparen token'>(</span><span class='symbol val'>:note</span><span class='rparen token'>)</span> <span class='rbrace token'>}</span>

          <span class='context identifier id'>context</span> <span class='string val'>&quot;on GET to /notes/:id&quot;</span> <span class='do do kw'>do</span>
            <span class='setup identifier id'>setup</span> <span class='lbrace token'>{</span> <span class='get identifier id'>get</span> <span class='symbol val'>:show</span><span class='comma token'>,</span> <span class='symbol val'>:id</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='@note ivar id'>@note</span> <span class='rbrace token'>}</span>
            <span class='should_be_denied_as_user identifier id'>should_be_denied_as_user</span>
          <span class='end end kw'>end</span>
          <span class='dot3 op'>...</span>
        <span class='end end kw'>end</span>
      <span class='end end kw'>end</span>
    <span class='end end kw'>end</span>

    <span class='as_a_visitor identifier id'>as_a_visitor</span> <span class='do do kw'>do</span>
      <span class='who_cannot_manage identifier id'>who_cannot_manage</span> <span class='symbol val'>:notes</span> <span class='do do kw'>do</span>
        <span class='context identifier id'>context</span> <span class='string val'>&quot;on GET to /notes/new&quot;</span> <span class='do do kw'>do</span>
          <span class='setup identifier id'>setup</span> <span class='lbrace token'>{</span> <span class='get identifier id'>get</span> <span class='symbol val'>:new</span> <span class='rbrace token'>}</span>
          <span class='should_be_denied_as_visitor identifier id'>should_be_denied_as_visitor</span>
        <span class='end end kw'>end</span>

        <span class='context identifier id'>context</span> <span class='string val'>&quot;on POST to /notes&quot;</span> <span class='do do kw'>do</span>
          <span class='setup identifier id'>setup</span> <span class='lbrace token'>{</span> <span class='post identifier id'>post</span> <span class='symbol val'>:create</span><span class='comma token'>,</span> <span class='symbol val'>:note</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='lbrace token'>{</span><span class='rbrace token'>}</span> <span class='rbrace token'>}</span>
          <span class='should_be_denied_as_visitor identifier id'>should_be_denied_as_visitor</span>
        <span class='end end kw'>end</span>
        <span class='dot3 op'>...</span>
      <span class='end end kw'>end</span>
    <span class='end end kw'>end</span>
  <span class='end end kw'>end</span>
</pre>


  </div>
</div>
<div class="tags">
  
</div>


  <h2>Method Summary</h2>
  <ul class="summary">
    
      <li class="public ">
  <span class="summary_signature"><a href="#as_a_logged_in_user-class_method" title="as_a_logged_in_user (class method)">+ (Object) <strong>as_a_logged_in_user</strong>(&amp;blk) </a>
  
  </span>
  
  
  
  

  
    <span class="summary_desc">
Context macro that creates a logged in user .

</span>
  
</li>

    
      <li class="public ">
  <span class="summary_signature"><a href="#as_a_visitor-class_method" title="as_a_visitor (class method)">+ (Object) <strong>as_a_visitor</strong>(&amp;blk) </a>
  
  </span>
  
  
  
  

  
    <span class="summary_desc">
Context macro that ensures there is no logged in user.

</span>
  
</li>

    
      <li class="public ">
  <span class="summary_signature"><a href="#should_be_denied_as_user-class_method" title="should_be_denied_as_user (class method)">+ (Object) <strong>should_be_denied_as_user</strong> </a>
  
  </span>
  
  
  
  

  
    <span class="summary_desc">
Should statement that ensures that the user is denied access after trying
to reach a protected page.

</span>
  
</li>

    
      <li class="public ">
  <span class="summary_signature"><a href="#should_be_denied_as_visitor-class_method" title="should_be_denied_as_visitor (class method)">+ (Object) <strong>should_be_denied_as_visitor</strong> </a>
  
  </span>
  
  
  
  

  
    <span class="summary_desc">
Should statement that ensures that the visitor is denied access after
trying to reach a protected page.

</span>
  
</li>

    
      <li class="public ">
  <span class="summary_signature"><a href="#who_can_manage-class_method" title="who_can_manage (class method)">+ (Object) <strong>who_can_manage</strong>(plural_model_name, &amp;blk) </a>
  
  </span>
  
  
  
  

  
    <span class="summary_desc">
Context macro that ensures that the @logged_in_user is authorized on all
actions for the given model.

</span>
  
</li>

    
      <li class="public ">
  <span class="summary_signature"><a href="#who_cannot_manage-class_method" title="who_cannot_manage (class method)">+ (Object) <strong>who_cannot_manage</strong>(plural_model_name, &amp;blk) </a>
  
  </span>
  
  
  
  

  
    <span class="summary_desc">
Context macro that ensures that the @logged_in_user is not authorized on
all actions for the given model.

</span>
  
</li>

    
      <li class="public ">
  <span class="summary_signature"><a href="#login_as-instance_method" title="#login_as (instance method)">- (User) <strong>login_as</strong>(user) </a>
  
  </span>
  
  
  
  

  
    <span class="summary_desc">
Helper method that logs the given user in.

</span>
  
</li>

    
      <li class="public ">
  <span class="summary_signature"><a href="#logout-instance_method" title="#logout (instance method)">- (nil) <strong>logout</strong> </a>
  
  </span>
  
  
  
  

  
    <span class="summary_desc">
Helper method that removes any logged in sessions.

</span>
  
</li>

    
      <li class="public ">
  <span class="summary_signature"><a href="#stub_all_authorization_methods_on_class-instance_method" title="#stub_all_authorization_methods_on_class (instance method)">- (Object) <strong>stub_all_authorization_methods_on_class</strong>(klass, user, return_value) </a>
  
  </span>
  
  
  
  

  
    <span class="summary_desc">
Helper method for <tt>who_can_manage</tt> and <tt>who_cannot_manage</tt>
that takes care of stubbing out the authorization methods.

</span>
  
</li>

    
  </ul>



  <div id="method_details">
    <h2>Method Details</h2>
    
      <div class="method_details first">
  <p class="signature first" id="as_a_logged_in_user-class_method">
  
    + (<tt>Object</tt>) <strong>as_a_logged_in_user</strong>(&amp;blk) 
  

  
</p><div class="docstring">
  <div class="discussion">
    <p>
Context macro that creates a logged in user
</p>
<p>
It uses the :user Factory Girl factory (which must exist) and assigns the
user to @logged_in_user
</p>


  </div>
</div>
<div class="tags">
  <h3>Yields:</h3>
<ul class="yield">
  
    <li>
      
        <span class='type'></span>
      
      
      
      
        
        
Block for adding other should and context statements.


      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


62
63
64
65
66
67</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'shoulda_macros/controller_macros.rb', line 62</span>

<span class='def def kw'>def</span> <span class='self self kw'>self</span><span class='dot token'>.</span><span class='as_a_logged_in_user identifier id'>as_a_logged_in_user</span><span class='lparen token'>(</span><span class='bitand op'>&amp;</span><span class='blk identifier id'>blk</span><span class='rparen token'>)</span>
  <span class='context identifier id'>context</span> <span class='string val'>&quot;as a logged in user&quot;</span> <span class='do do kw'>do</span>
    <span class='setup identifier id'>setup</span> <span class='lbrace token'>{</span> <span class='@logged_in_user ivar id'>@logged_in_user</span> <span class='assign token'>=</span> <span class='login_as identifier id'>login_as</span> <span class='Factory constant id'>Factory</span><span class='lparen token'>(</span><span class='symbol val'>:user</span><span class='rparen token'>)</span> <span class='rbrace token'>}</span>
    <span class='merge_block identifier id'>merge_block</span><span class='lparen token'>(</span><span class='bitand op'>&amp;</span><span class='blk identifier id'>blk</span><span class='rparen token'>)</span>
  <span class='end end kw'>end</span>
<span class='end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="as_a_visitor-class_method">
  
    + (<tt>Object</tt>) <strong>as_a_visitor</strong>(&amp;blk) 
  

  
</p><div class="docstring">
  <div class="discussion">
    <p>
Context macro that ensures there is no logged in user
</p>


  </div>
</div>
<div class="tags">
  <h3>Yields:</h3>
<ul class="yield">
  
    <li>
      
        <span class='type'></span>
      
      
      
      
        
        
Block for adding other should and context statements.


      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


72
73
74
75
76
77</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'shoulda_macros/controller_macros.rb', line 72</span>

<span class='def def kw'>def</span> <span class='self self kw'>self</span><span class='dot token'>.</span><span class='as_a_visitor identifier id'>as_a_visitor</span><span class='lparen token'>(</span><span class='bitand op'>&amp;</span><span class='blk identifier id'>blk</span><span class='rparen token'>)</span>
  <span class='context identifier id'>context</span> <span class='string val'>&quot;as a visitor&quot;</span> <span class='do do kw'>do</span>
    <span class='setup identifier id'>setup</span> <span class='lbrace token'>{</span> <span class='logout identifier id'>logout</span> <span class='rbrace token'>}</span>
    <span class='merge_block identifier id'>merge_block</span><span class='lparen token'>(</span><span class='bitand op'>&amp;</span><span class='blk identifier id'>blk</span><span class='rparen token'>)</span>
  <span class='end end kw'>end</span>
<span class='end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="should_be_denied_as_user-class_method">
  
    + (<tt>Object</tt>) <strong>should_be_denied_as_user</strong> 
  

  
</p><div class="docstring">
  <div class="discussion">
    <p>
Should statement that ensures that the user is denied access after trying
to reach a protected page.
</p>
<p>
It ensures the user is redirected to the
permission_denied_redirect_for_user url and that the
permission_denied_flash_for_user flash message is set.
</p>


  </div>
</div>
<div class="tags">
  
</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


131
132
133
134
135
136
137
138
139</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'shoulda_macros/controller_macros.rb', line 131</span>

<span class='def def kw'>def</span> <span class='self self kw'>self</span><span class='dot token'>.</span><span class='should_be_denied_as_user identifier id'>should_be_denied_as_user</span>
  <span class='should identifier id'>should</span> <span class='string val'>&quot;tell the user they aren't authorized&quot;</span> <span class='do do kw'>do</span>
    <span class='assert_contains identifier id'>assert_contains</span> <span class='flash identifier id'>flash</span><span class='dot token'>.</span><span class='values identifier id'>values</span><span class='comma token'>,</span> <span class='@controller ivar id'>@controller</span><span class='dot token'>.</span><span class='send identifier id'>send</span><span class='lparen token'>(</span><span class='symbol val'>:permission_denied_flash_for_user</span><span class='rparen token'>)</span>
  <span class='end end kw'>end</span>

  <span class='should identifier id'>should</span> <span class='string val'>&quot;redirect user due to authorization&quot;</span> <span class='do do kw'>do</span>
    <span class='assert_redirected_to identifier id'>assert_redirected_to</span> <span class='@controller ivar id'>@controller</span><span class='dot token'>.</span><span class='send identifier id'>send</span><span class='lparen token'>(</span><span class='symbol val'>:permission_denied_redirect_for_user</span><span class='rparen token'>)</span>
  <span class='end end kw'>end</span>
<span class='end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="should_be_denied_as_visitor-class_method">
  
    + (<tt>Object</tt>) <strong>should_be_denied_as_visitor</strong> 
  

  
</p><div class="docstring">
  <div class="discussion">
    <p>
Should statement that ensures that the visitor is denied access after
trying to reach a protected page.
</p>
<p>
It ensures the visitor is redirected to the
<tt>@controller.permission_denied_redirect_for_visitor</tt> url and that
the flash is set to
<tt>@controller.permission_denied_flash_for_visitor</tt>.
</p>


  </div>
</div>
<div class="tags">
  
</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


147
148
149
150
151
152
153
154
155</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'shoulda_macros/controller_macros.rb', line 147</span>

<span class='def def kw'>def</span> <span class='self self kw'>self</span><span class='dot token'>.</span><span class='should_be_denied_as_visitor identifier id'>should_be_denied_as_visitor</span>
  <span class='should identifier id'>should</span> <span class='string val'>&quot;tell the visitor they aren't authorized&quot;</span> <span class='do do kw'>do</span>
    <span class='assert_contains identifier id'>assert_contains</span> <span class='flash identifier id'>flash</span><span class='dot token'>.</span><span class='values identifier id'>values</span><span class='comma token'>,</span> <span class='@controller ivar id'>@controller</span><span class='dot token'>.</span><span class='send identifier id'>send</span><span class='lparen token'>(</span><span class='symbol val'>:permission_denied_flash_for_visitor</span><span class='rparen token'>)</span>
  <span class='end end kw'>end</span>

  <span class='should identifier id'>should</span> <span class='string val'>&quot;redirect visitor due to authorization&quot;</span> <span class='do do kw'>do</span>
    <span class='assert_redirected_to identifier id'>assert_redirected_to</span> <span class='@controller ivar id'>@controller</span><span class='dot token'>.</span><span class='send identifier id'>send</span><span class='lparen token'>(</span><span class='symbol val'>:permission_denied_redirect_for_visitor</span><span class='rparen token'>)</span>
  <span class='end end kw'>end</span>
<span class='end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="who_can_manage-class_method">
  
    + (<tt>Object</tt>) <strong>who_can_manage</strong>(plural_model_name, &amp;blk) 
  

  
</p><div class="docstring">
  <div class="discussion">
    <p>
Context macro that ensures that the @logged_in_user is authorized on all
actions for the given model.
</p>
<p>
This macro makes use of Mocha stubbing to force all of the authorization
methods on the given model to return true for the @logged_in_user instance.
It is meant to be used in conjunction with <tt>as_a_visitor</tt> and
<tt>as_a_logged_in_user</tt>.
</p>


  </div>
</div>
<div class="tags">
  <h3>Parameters:</h3>
<ul class="param">
  
    <li>
      
        <span class='type'>(<tt>Symbol</tt>)</span>
      
      
        <span class='name'>plural_model_name</span>
      
      
      
        &mdash;
        
The pluralized name of the model that the @logged_in_user instance should
be allowed to manage.


      
    </li>
  
</ul>
<h3>Yields:</h3>
<ul class="yield">
  
    <li>
      
        <span class='type'></span>
      
      
      
      
        
        
Block for adding other should and context statements.


      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


92
93
94
95
96
97
98
99
100</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'shoulda_macros/controller_macros.rb', line 92</span>

<span class='def def kw'>def</span> <span class='self self kw'>self</span><span class='dot token'>.</span><span class='who_can_manage identifier id'>who_can_manage</span><span class='lparen token'>(</span><span class='plural_model_name identifier id'>plural_model_name</span><span class='comma token'>,</span> <span class='bitand op'>&amp;</span><span class='blk identifier id'>blk</span><span class='rparen token'>)</span>
  <span class='context identifier id'>context</span> <span class='dstring node'>&quot;who can manage #{plural_model_name}&quot;</span> <span class='do do kw'>do</span>
    <span class='setup identifier id'>setup</span> <span class='do do kw'>do</span>
      <span class='klass identifier id'>klass</span> <span class='assign token'>=</span> <span class='plural_model_name identifier id'>plural_model_name</span><span class='dot token'>.</span><span class='to_s identifier id'>to_s</span><span class='dot token'>.</span><span class='singularize identifier id'>singularize</span><span class='dot token'>.</span><span class='camelcase identifier id'>camelcase</span><span class='dot token'>.</span><span class='constantize identifier id'>constantize</span>
      <span class='stub_all_authorization_methods_on_class identifier id'>stub_all_authorization_methods_on_class</span><span class='lparen token'>(</span><span class='klass identifier id'>klass</span><span class='comma token'>,</span> <span class='@logged_in_user ivar id'>@logged_in_user</span><span class='comma token'>,</span> <span class='true true kw'>true</span><span class='rparen token'>)</span>
    <span class='end end kw'>end</span>
    <span class='merge_block identifier id'>merge_block</span><span class='lparen token'>(</span><span class='bitand op'>&amp;</span><span class='blk identifier id'>blk</span><span class='rparen token'>)</span>
  <span class='end end kw'>end</span>
<span class='end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="who_cannot_manage-class_method">
  
    + (<tt>Object</tt>) <strong>who_cannot_manage</strong>(plural_model_name, &amp;blk) 
  

  
</p><div class="docstring">
  <div class="discussion">
    <p>
Context macro that ensures that the @logged_in_user is not authorized on
all actions for the given model.
</p>
<p>
This macro makes use of Mocha stubbing to force all of the authorization
methods on the given model to return false for the @logged_in_user
instance. It is meant to be used in conjunction with <tt>as_a_visitor</tt>
and <tt>as_a_logged_in_user</tt>.
</p>


  </div>
</div>
<div class="tags">
  <h3>Parameters:</h3>
<ul class="param">
  
    <li>
      
        <span class='type'>(<tt>Symbol</tt>)</span>
      
      
        <span class='name'>plural_model_name</span>
      
      
      
        &mdash;
        
The pluralized name of the model that the @logged_in_user instance should
not be allowed to manage.


      
    </li>
  
</ul>
<h3>Yields:</h3>
<ul class="yield">
  
    <li>
      
        <span class='type'></span>
      
      
      
      
        
        
Block for adding other should and context statements.


      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


115
116
117
118
119
120
121
122
123</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'shoulda_macros/controller_macros.rb', line 115</span>

<span class='def def kw'>def</span> <span class='self self kw'>self</span><span class='dot token'>.</span><span class='who_cannot_manage identifier id'>who_cannot_manage</span><span class='lparen token'>(</span><span class='plural_model_name identifier id'>plural_model_name</span><span class='comma token'>,</span> <span class='bitand op'>&amp;</span><span class='blk identifier id'>blk</span><span class='rparen token'>)</span>
  <span class='context identifier id'>context</span> <span class='dstring node'>&quot;who can't manage #{plural_model_name}&quot;</span> <span class='do do kw'>do</span>
    <span class='setup identifier id'>setup</span> <span class='do do kw'>do</span>
      <span class='klass identifier id'>klass</span> <span class='assign token'>=</span> <span class='plural_model_name identifier id'>plural_model_name</span><span class='dot token'>.</span><span class='to_s identifier id'>to_s</span><span class='dot token'>.</span><span class='singularize identifier id'>singularize</span><span class='dot token'>.</span><span class='camelcase identifier id'>camelcase</span><span class='dot token'>.</span><span class='constantize identifier id'>constantize</span>
      <span class='stub_all_authorization_methods_on_class identifier id'>stub_all_authorization_methods_on_class</span><span class='lparen token'>(</span><span class='klass identifier id'>klass</span><span class='comma token'>,</span> <span class='@logged_in_user ivar id'>@logged_in_user</span><span class='comma token'>,</span> <span class='false false kw'>false</span><span class='rparen token'>)</span>
    <span class='end end kw'>end</span>
    <span class='merge_block identifier id'>merge_block</span><span class='lparen token'>(</span><span class='bitand op'>&amp;</span><span class='blk identifier id'>blk</span><span class='rparen token'>)</span>
  <span class='end end kw'>end</span>
<span class='end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="login_as-instance_method">
  
    - (<tt>User</tt>) <strong>login_as</strong>(user) 
  

  
</p><div class="docstring">
  <div class="discussion">
    <p>
Helper method that logs the given user in.
</p>


  </div>
</div>
<div class="tags">
  <h3>Parameters:</h3>
<ul class="param">
  
    <li>
      
        <span class='type'>(<tt>User</tt>)</span>
      
      
        <span class='name'>user</span>
      
      
      
        &mdash;
        
User that is logged in.


      
    </li>
  
</ul>
<h3>Returns:</h3>
<ul class="return">
  
    <li>
      
        <span class='type'>(<tt>User</tt>)</span>
      
      
      
      
        &mdash;
        
The same user


      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


170
171
172
173</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'shoulda_macros/controller_macros.rb', line 170</span>

<span class='def def kw'>def</span> <span class='login_as identifier id'>login_as</span><span class='lparen token'>(</span><span class='user identifier id'>user</span><span class='rparen token'>)</span>
  <span class='UserSession constant id'>UserSession</span><span class='dot token'>.</span><span class='create identifier id'>create</span><span class='lparen token'>(</span><span class='user identifier id'>user</span><span class='rparen token'>)</span>
  <span class='return return kw'>return</span> <span class='user identifier id'>user</span>
<span class='end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="logout-instance_method">
  
    - (<tt>nil</tt>) <strong>logout</strong> 
  

  
</p><div class="docstring">
  <div class="discussion">
    <p>
Helper method that removes any logged in sessions.
</p>


  </div>
</div>
<div class="tags">
  <h3>Returns:</h3>
<ul class="return">
  
    <li>
      
        <span class='type'>(<tt>nil</tt>)</span>
      
      
      
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


177
178
179
180</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'shoulda_macros/controller_macros.rb', line 177</span>

<span class='def def kw'>def</span> <span class='logout identifier id'>logout</span>
  <span class='UserSession constant id'>UserSession</span><span class='dot token'>.</span><span class='find identifier id'>find</span> <span class='andop op'>&amp;&amp;</span> <span class='UserSession constant id'>UserSession</span><span class='dot token'>.</span><span class='find identifier id'>find</span><span class='dot token'>.</span><span class='destroy identifier id'>destroy</span>
  <span class='return return kw'>return</span> <span class='nil nil kw'>nil</span>
<span class='end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="stub_all_authorization_methods_on_class-instance_method">
  
    - (<tt>Object</tt>) <strong>stub_all_authorization_methods_on_class</strong>(klass, user, return_value) 
  

  
</p><div class="docstring">
  <div class="discussion">
    <p>
Helper method for <tt>who_can_manage</tt> and <tt>who_cannot_manage</tt>
that takes care of stubbing out the authorization methods.
</p>


  </div>
</div>
<div class="tags">
  
</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


159
160
161
162
163
164</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'shoulda_macros/controller_macros.rb', line 159</span>

<span class='def def kw'>def</span> <span class='stub_all_authorization_methods_on_class identifier id'>stub_all_authorization_methods_on_class</span><span class='lparen token'>(</span><span class='klass identifier id'>klass</span><span class='comma token'>,</span> <span class='user identifier id'>user</span><span class='comma token'>,</span> <span class='return_value identifier id'>return_value</span><span class='rparen token'>)</span>
  <span class='klass identifier id'>klass</span><span class='dot token'>.</span><span class='stubs identifier id'>stubs</span><span class='lparen token'>(</span><span class='symbol val'>:creatable_by?</span><span class='rparen token'>)</span><span class='dot token'>.</span><span class='with identifier id'>with</span><span class='lparen token'>(</span><span class='user identifier id'>user</span><span class='rparen token'>)</span><span class='dot token'>.</span><span class='returns identifier id'>returns</span><span class='lparen token'>(</span><span class='return_value identifier id'>return_value</span><span class='rparen token'>)</span>
  <span class='klass identifier id'>klass</span><span class='dot token'>.</span><span class='any_instance identifier id'>any_instance</span><span class='dot token'>.</span><span class='stubs identifier id'>stubs</span><span class='lparen token'>(</span><span class='symbol val'>:editable_by?</span><span class='rparen token'>)</span><span class='dot token'>.</span><span class='with identifier id'>with</span><span class='lparen token'>(</span><span class='user identifier id'>user</span><span class='rparen token'>)</span><span class='dot token'>.</span><span class='returns identifier id'>returns</span><span class='lparen token'>(</span><span class='return_value identifier id'>return_value</span><span class='rparen token'>)</span>
  <span class='klass identifier id'>klass</span><span class='dot token'>.</span><span class='any_instance identifier id'>any_instance</span><span class='dot token'>.</span><span class='stubs identifier id'>stubs</span><span class='lparen token'>(</span><span class='symbol val'>:readable_by?</span><span class='rparen token'>)</span><span class='dot token'>.</span><span class='with identifier id'>with</span><span class='lparen token'>(</span><span class='user identifier id'>user</span><span class='rparen token'>)</span><span class='dot token'>.</span><span class='returns identifier id'>returns</span><span class='lparen token'>(</span><span class='return_value identifier id'>return_value</span><span class='rparen token'>)</span>
  <span class='klass identifier id'>klass</span><span class='dot token'>.</span><span class='any_instance identifier id'>any_instance</span><span class='dot token'>.</span><span class='stubs identifier id'>stubs</span><span class='lparen token'>(</span><span class='symbol val'>:destroyable_by?</span><span class='rparen token'>)</span><span class='dot token'>.</span><span class='with identifier id'>with</span><span class='lparen token'>(</span><span class='user identifier id'>user</span><span class='rparen token'>)</span><span class='dot token'>.</span><span class='returns identifier id'>returns</span><span class='lparen token'>(</span><span class='return_value identifier id'>return_value</span><span class='rparen token'>)</span>
<span class='end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
  </div>

</div>
    
    <div id="footer">
  Generated on Wed Dec 23 03:17:31 2009 by 
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool">yard</a>
  0.4.0 (ruby-1.8.6).
</div>

  </body>
</html>